<template>
  <div class="risk">
    <van-search
      class="info_search"
      v-model="value"
      @search="onSearch"
      @clear="clearSearch"
      placeholder="搜索"
    />
    <van-list
      style="margin-top: 10px"
      :finished="finished"
      v-model="loading"
      finished-text="没有更多了"
    >
      <van-cell
        v-for="(item, index) in list"
        :key="index"
        @click="handleChange(item)"
      >
        <div class="risk_item">
          <div>
            <div class="mb-10">{{ item.ChnName }}</div>
            <div>
              {{ item.OrgFullName }}{{ item.OrgFullName != null ? ">" : ""
              }}{{ item.PostName }}
            </div>
          </div>
        </div>
      </van-cell>
    </van-list>

    <!-- <div class="risk_item_radio">
            <div>
                <div class="mb-10">所有部门</div>
                <div>所有部门</div>
            </div>
       <van-checkbox name="{a:ggg,c:xxx}"></van-checkbox>
        </div>
        <div class="risk_item_radio">
            <div>
                <div class="mb-10">所有部门</div>
                <div>所有部门</div>
            </div>
         <van-checkbox name="{a:ggg,c:xxx}"></van-checkbox>
        </div> -->
  </div>
</template>

<script>
import { getChooseUserList } from "@/api/common";
export default {
  data() {
    return {
      list: [],
      options: [],
      result: "",
      id: this.$route.query.id,
      loading: false,
      finished: false,
      code: this.$route.query.code,
      name: this.$route.query.name,
      filter: {
        dataType: "List",
        allDefault: true,
        userKind: 16,
        accounted: false,
      },
      activeNames: ["1"],
      border: false,
      value: "",
      radio: "",
    };
  },
  created() {
    this.getList();
  },

  methods: {
    onSearch(val) {
      if (val) {
        this.list = this.fuzzyQuery(this.options, val, "ChnName");
      } else {
        this.list = this.options;
      }
    },
    clearSearch() {
      this.list = this.options;
    },
    fuzzyQuery(list, keyWord, type) {
      var arr = [];
      list.map((item) => {
        if (item[type].indexOf(keyWord) >= 0) {
          arr.push(item);
        }
      });

      return arr;
    },

    getList() {
      this.loading = true;
      getChooseUserList(this.filter)
        .then((res) => {
          this.loading = false;
          this.list = res.data;
          this.options = res.data;
          this.finished = true;
          //this.filter.page = res.data.PageIndex;
        })
        .catch((err) => {
          this.finished = true;
        });
    },
    // 选择人员
    handleChange(item) {
      this.$emit("cbCert", item);
    },
  },
};
</script>

<style lang="less" scoped>
.risk {
  height: 100vh;
  background-color: #e8f1f8;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}
.risk_item {
  width: 100%;
  padding: 10px 20px;
  background-color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
